<template>
	<view class="all-main">
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="欢迎进入风动社区"></u-loading-page>
		<view v-if="!loadding" class="main">
			<view class="title">
				您遇到了什么问题？
			</view>
			<u-line></u-line>
			<view class="tags">
				<view v-for="(item, index) in tagList" :key="index" class="tag-item" @click="tagClick(item)">
					<text :class="item.select == 2 ? 'active' : ''">{{item.title}}</text>
				</view>
			</view>
			<view class="description">
				<u--textarea v-model="description" placeholder="写其他意见和建议" height="120" maxlength="100" count></u--textarea>
			</view>
			<view class="msg">
				请您详细描述您所遇到的问题，提交成功后，客服将在3分钟内给您打电话处理，请您注意接收客服电话。
			</view>
			<view class="btn" @click="btnSave">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadding: false,
				tagList: [],
				description: '',
				is_true: true,
				tags: [],
				sn: '',
				userinfo: {},
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo');
			this.getQuestion()
		},
		methods: {
			// 加载服务类型
			async getQuestion() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'v1/getQuestion',
					data: {
						type: 'kefu'
					},
					header: {
						'token': this.userinfo.token
					}
				});
				if (res.code == 1) {
					res.data.map(item => {
						item.select = 1
					})
					this.tagList = res.data
				}
			},
			// 选择标签
			tagClick(item) {
				var index = this.tags.indexOf(item.id);
				if (item.select == 1) {
					item.select = 2
					if (index <= -1) {
						this.tags.push(item.id)
					}
				} else {
					item.select = 1
					if (index > -1) {
						this.tags.splice(index, 1);
					}
				}
			},
			// 确认提交
			btnSave() {
				var that = this
				uni.showModal({
					title: '提示',
					content: '确定提交吗？',
					success: function(res) {
						if (res.confirm) {
							that.btnSaveFun()
						}
					}
				});
			},
			// 提交申领 - 方法
			async btnSaveFun() {
				var that = this
				if (this.is_true) {
					this.is_true = false
					uni.showLoading({
						title: '加载中'
					});
					const {
						data: res
					} = await this.$myHttp5({
						url: 'Systemser/customer_back_problem',
						data: {
							classId: this.tags,
							content: this.description
						},
						header: {
							'token': this.userinfo.token
						}
					});
					this.is_true = true
					uni.hideLoading()
					uni.showToast({
						title: res.msg,
						icon: "none"
					});
					if (res.code == 1) {
						setTimeout(function() {
							uni.switchTab({
								url: '/pages/index/index'
							})
						},1500)
					}
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.all-main {
		.main {
			padding: 30rpx;
			
			.title {
				padding-bottom: 20rpx;
				color: #c8c9cc;
			}
			
			.items {
				display: flex;
				justify-content: space-between;
				box-shadow: 0px 0px 20px -12px #342f2f;
				padding: 30rpx;
				margin-bottom: 30rpx;
				color: #ffffff;
				border-radius: 12rpx;
				
				.lefts {
					width: 85%;
					.name {
						font-weight: bold;
						padding-bottom: 20rpx;
					}
					.description {
						padding-top: 20rpx;
						font-size: 24rpx;
					}
				}
				
				.rights {
					display: flex;
					justify-items: center;
				}
			}
			
			.bg-1 {
				background-color: #2979ff;
			}
			
			.bg-2 {
				background-color: #fa3534;
			}
			
			.bg-3 {
				background-color: #ff9900;
			}
			
			.bg-4 {
				background-color: #19be6b;
			}

			.tags {
				padding-top: 10rpx;
				display: flex;
				flex-wrap: wrap;
				
				.tag-item {
					width: 33%;
					text-align: center;
					padding: 20rpx 0;
					
					text {
						border-radius: 20rpx;
						background-color: #fdf6ec;
						color: #ff9900;
						font-size: 28rpx;
						padding: 10rpx 20rpx;
					}
					
					.active {
						background-color: #ff9900;
						color: #ffffff;
					}
				}
			}
			
			.description {
				padding: 30rpx 0;
			}
			
			.msg {
				padding: 10rpx 0;
				font-size: 26rpx;
				color: #fa3534;
			}
			
			.btn {
				margin-top: 30rpx;
				text-align: center;
				background-color: #ff9900;
				color: #ffffff;
				padding: 30rpx;
				border-radius: 10rpx;
			}
		}
	}
</style>